import Page
from Page import Personal
from Base.Base import Base
from selenium.webdriver.common.by import By


class PersonalListenSongsPage(Base):
    """
    个人中心听歌识曲
    """

    def __init__(self, driver):
        Base.__init__(self, driver)

        # 关闭按钮
        self.listen_close_btn = (By.XPATH, Personal.RESOURCE_ID_LAUNCHER.format("iv_music_rec_close"))

        # 听歌识曲图标
        self.listen_song_icon = (By.XPATH, Personal.RESOURCE_ID_LAUNCHER.format("rec_anim_img"))

        # 识别提示语
        self.listen_recognition_prompt_text = (By.XPATH, Personal.RESOURCE_ID_LAUNCHER.format("tv_music_rec_iat"))

        # 识别提示
        self.listen_recognition_prompt_tip_text = (By.XPATH, Personal.RESOURCE_ID_LAUNCHER.format("tv_error_tip"))

        # 识别记录按钮
        self.listen_identify_record_button_btn = (By.XPATH, Personal.identify_record_button.format(""))

    def get_song(self):
        """
        获取听歌识曲图标

        :return:
        """
        return self.find_element_o(self.listen_song_icon)

    def get_recognition_prompt(self):
        """
        获取识别提示语

        :return:
        """
        return self.find_element_o(self.listen_recognition_prompt_text)

    def get_recognition_prompt_tip(self):
        """
        获取识别提示

        :return:
        """
        return self.find_element_o(self.listen_recognition_prompt_tip_text)

    def click_identify_record_button(self, index=1):
        """
        点击识别记录按钮

        :return:
        """
        self.listen_identify_record_button_btn = (By.XPATH, Personal.identify_record_button.format(index))
        self.click_element(self.listen_identify_record_button_btn)

    def is_display_personal_song(self):
        """
        是否存在听歌识曲页

        :return: bool
        """
        return self.is_display(self.listen_song_icon)
